<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>项目信息</title>
<block th:replace="commonBase"></block>  
</head>
<link rel="stylesheet" th:href="@{/common/css/fileIcon.css}"/>
<body>

    <!-- 菜单栏开始 -->
	<div style="width:100%;">
		<div class="mini-toolbar" style="padding:0px;">
			<table style="width:100%;">  
				<tr>    
					<td style="width:100%">       
						<a sec:authorize="hasAuthority('jhsb:xmxx:add')" class="mini-button" plain="true" onclick="add()" iconCls="icon-addnew">添加</a>
					</td>
					<td style="white-space:nowrap;">     
						<input id="searchKey" class="mini-textbox" emptyText="请输入项目名称或编码" style="width:160px;" onenter="search"/>
				 		<a class="mini-button" onclick="search()" iconCls="icon-search">查询</a>         
					</td> 
				</tr>  
			</table>
		</div>
	</div>
	<!-- 菜单栏结束 -->   
	
	<!-- 列表展示开始 -->
	<div class="mini-fit">             
         <div id="grid_pro" class="mini-datagrid"  sortField="plan_pro_year" sortOrder="desc" idField="guid" onrowdblclick="onDoubleClick"     
			style="width:100%;height:100%;" borderStyle="border:1;" showPager="true" pageSize="20" multiselect="true"  
		    allowResize="true" expandOnLoad="true" th:attr="url=@{/roadMonitor/planDeclare/pagelist}">
			<div property="columns">      
			    <div type="indexcolumn"></div>              
				<div field="planProName" width="210" headerAlign="center" align="left">项目名称</div>  			      
				<div field="planProId" width="100" headerAlign="center" align="left">项目编码</div>               
				<div field="planProYear" width="80" headerAlign="center" align="center">申报年度</div> 
				<div field="planProDate" width="100" headerAlign="center" align="center" renderer="formatDate">申报时间</div>  
				<div field="createUserName" width="120" headerAlign="center" align="left">创建人</div>                
				<div field="createTime" width="100" headerAlign="center" align="center" renderer="formatDate">创建时间</div>
				<div field="updateUserName" width="120" headerAlign="center" align="left" >最近更新人</div>             
				<div field="updateTime" width="100" headerAlign="center" align="center" renderer="formatDate">最近更新时间</div>
				<div sec:authorize="hasAuthority('jhsb:xmxx:operate')" field="action" width="90" headerAlign="center" renderer="onRenderer" align="center">操作</div>
				<div field="remark" width="200" headerAlign="center" align="left">备注</div>   
			</div>     
         </div>  
    </div>
    <!-- 列表展示结束 -->  
</body>
<script  th:inline="javascript" type="text/javascript">
 /*<![CDATA[*/ 
	 
	var grid = null;
	$(function(){  
		mini.parse();    
		grid = mini.get("grid_pro");
		search();
	})
	
	function search(){
		var searchKey = mini.get("searchKey").getValue();
		grid.load({"searchPhrase":searchKey});      
	}
	
	function onDoubleClick(){      
	    var row = grid.getSelected();
		$.ajax({
			url:basePath+"roadMonitor/planDeclare/updatePlanSelect",
		    type:"post",
		    data:{guid:row.guid},
		    success:function(successData){
		    	var message = mini.decode(successData);
		    	if(message.type=='200'){      
		    		showMsg("双击事件成功！项目【"+row.planProName+"】在后续下拉框中优先排在第一位","success",2400,"center","center");
		    	}else{
		    		showMsg("双击事件失败","warning",1200,"center","center");
		    	}
		    },  
		    error:function(errorData){     
		    	showMsg("双击事件错误，请稍后重试...","danger",800,"center","center");
		    }
		})       
	}
	
	function formatDate(e){
		var dateLong = e.value;
		if(!dateLong){
			return "";  
		}    
		return format(dateLong,'yyyy-MM-dd');            
	}

    function onRenderer(e){
      	var field = e.field;
  		var text = "";
  		if(field == "action"){            
  			text="<a class='funceditcls' href='javascript:void(0);' onclick=\"edit()\">编辑</a><a class='funceditcls' href='javascript:void(0);'  style='padding-left:10px;' onclick=\"remove()\">删除</a>";
  		}
  		return text;
     }

     function add(e){
    	 mini.open({
    	        url:basePath+"roadMonitor/planDeclare/plan_add",
    	        title: "新增计划申报项目",
    	        width: 580,
    	        height: 400,  
      	        showMaxButton: false,        
      	        allowResize:false, 
    	        onload: function () {
    	            var iframe = this.getIFrameEl();
    	            var data = { action:"new"};
    	            iframe.contentWindow.setData(data);
    	        },
    	        ondestroy: function (action) {
    				if (action != "close" && action != "cancle"){
    	        		grid.reload();
    				}
    	        }
    	    });
    }
         
    function edit(){
    	var row =grid.getSelected();  
    	mini.open({
	        url:basePath+"roadMonitor/planDeclare/plan_add",
	        title: "编辑计划申报项目", width: 580, height: 400,    
	        onload: function () {
	            var iframe = this.getIFrameEl();
	            var data = { action:"edit",row:row};
	            iframe.contentWindow.setData(data);
	        },
	        ondestroy: function (action) {
				if (action != "close" && action != "cancle"){
					grid.reload();  
				}
	        }
	    });
    }  
     
    function remove(){
    	mini.confirm("确定要删除此条记录?","温馨提示",function(e){
    		if(e == "ok"){
    			var row = grid.getSelected();
    		    mini.mask({
    		        el: document.body,
    		        cls: 'mini-mask-loading',
    		        html: '删除中...'
    		    });
    			$.ajax({
    				url:basePath+"roadMonitor/planDeclare/removePro",
    			    type:"post",
    			    data:{guid:row.guid},
    			    success:function(successData){
    			    	mini.unmask(document.body);
    			    	var message = mini.decode(successData);
    			    	if(message.type=='200'){
    			    		showMsg("项目信息删除成功","success",800,"center","center");
    			    	    search();
    			    	}else if(message.type=='400'){
    			    		showMsg("存在与此项目关联的文件或数据源，请先删除关联文件和数据再删除项目...","warning",2800,"center","center");
    			    	}else{
    			    		showMsg("项目信息删除失败","warning",800,"center","center");
    			    	}
    			    },  
    			    error:function(errorData){
    			        mini.unmask(document.body);
    			    	showMsg("项目信息删除错误","danger",800,"center","center");
    			    }
    			})
    		}
    	});  
    }
/*]]>*/
</script>
</html>